<?php
error_reporting(E_ALL ^ E_NOTICE);
set_time_limit(0);
$db_name="hero";  
 
$table_name="hero";  
 
$connection= @mysql_connect("localhost","root","root") or die(mysql_error());  
 
$db= @mysql_select_db($db_name,$connection) or die (mysql_error());  
 
$logdate =  mysql_query("SELECT DISTINCT date FROM `hero`");
$dateTime = date("Y-m-d",strtotime("-1 day"));

    //$deviceid = mysql_fetch_array($deviceid_query);
    //while($deviceid[deviceid])

while($everylogdate = mysql_fetch_array($logdate))
{
var_dump($everylogdate[date]);
  $deviceid_query = mysql_query("SELECT DISTINCT deviceid
FROM `hero`
WHERE cents099 >0
AND date BETWEEN date_sub( '$everylogdate[date]', INTERVAL 14
DAY ) AND DATE_SUB( '$everylogdate[date]', INTERVAL 7
DAY )
UNION
SELECT DISTINCT deviceid
FROM `hero`
WHERE Cents1999 >0
AND date BETWEEN date_sub( '$everylogdate[date]', INTERVAL 14
DAY ) AND DATE_SUB( '$everylogdate[date]', INTERVAL 7
DAY )
UNION
SELECT DISTINCT deviceid
FROM `hero`
WHERE Cents499 >0
AND date BETWEEN date_sub( '$everylogdate[date]', INTERVAL 14
DAY ) AND DATE_SUB( '$everylogdate[date]', INTERVAL 7
DAY )
UNION
SELECT DISTINCT deviceid
FROM `hero`
WHERE Cents4999 >0
AND date BETWEEN date_sub( '$everylogdate[date]', INTERVAL 14
DAY ) AND DATE_SUB( '$everylogdate[date]', INTERVAL 7
DAY )
UNION
SELECT DISTINCT deviceid
FROM `hero`
WHERE Cents9999 >0
AND date BETWEEN date_sub( '$everylogdate[date]', INTERVAL 14
DAY ) AND DATE_SUB( '$everylogdate[date]', INTERVAL 7
DAY )
 ");

  while($deviceid = mysql_fetch_array($deviceid_query)) {

 //var_dump($deviceid);
     mysql_query("INSERT INTO weekPay (deviceid,date) 
                    VALUES('$deviceid[deviceid]','$everylogdate[date]')") or die(mysql_error());
}

 
  
}


  // {
    //$first_query = mysql_query("SELECT RegisterDate FROM hero where deviceid = '$deviceid[deviceid]' limit 0,1 ");

   // $first = mysql_fetch_array($first_query);
  // mysql_query("update hero a1 inner join hero_query_temp_filter a2 using(deviceid) set a1.DailyGamingTime =a2.DailyGamingTime,a1.GamingTime =a2.GamingTime where a1.deviceid =  a2.deviceid and a1.date =  a2.date");
  //var_dump($deviceid[deviceid]);die;
//
  // }

//mysql_query("delete from hero where TotalExp = ''");
//mysql_close($con);
?>